#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    string addStrings(string num1, string num2) {
        int end1 = num1.size() - 1, end2 = num2.size() - 1;
        int temp = 0;
        string poi;
        while (end1 >= 0 && end2 >= 0)
        {
            int val = (num1[end1] - '0') + (num2[end2] - '0');
            val += temp;
            temp = 0;
            if (val >= 10)
            {
                temp = 1;
                val -= 10;
            }
            poi.insert(poi.begin(), val + '0');
            end1--;
            end2--;
        }

        while (end1 >= 0)
        {
            int val = num1[end1] - '0';
            val += temp;
            temp = 0;
            if (val >= 10)
            {
                temp = 1;
                val -= 10;
            }
            poi.insert(poi.begin(), val + '0');
            end1--;
        }
        while (end2 >= 0)
        {
            int val = num2[end2] - '0';
            val += temp;
            temp = 0;
            if (val >= 10)
            {
                temp = 1;
                val -= 10;
            }
            poi.insert(poi.begin(), val + '0');
            end2--;
        }

        if (temp == 1)
            poi.insert(poi.begin(), temp + '0');
        temp = 0;

        return poi;
    }
};